<template>
  <a-card :bordered='false'>
    <!-- 查询区域 -->
    <div class='table-page-search-wrapper'>
      <a-form layout='inline' @keyup.enter.native='searchQuery'>
        <a-row :gutter='24'>
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <a-form-item label='月份'>
              <a-input placeholder='请输入月份' v-model='queryParam.salTime'></a-input>
            </a-form-item>
          </a-col>
<!--          <a-col :xl="6" :lg="7" :md="8" :sm="24">-->
<!--            <a-form-item label="是否发放">-->
<!--              <j-dict-select-tag placeholder="请选择" v-model="queryParam.issue" dictCode="switch_status" />-->
<!--            </a-form-item>-->
<!--          </a-col>-->
          <a-col :xl='6' :lg='7' :md='8' :sm='24'>
            <span style='float: left;overflow: hidden;' class='table-page-search-submitButtons'>
              <a-button type='primary' @click='searchQuery' icon='search'>查询</a-button>
              <a-button type='primary' @click='searchReset' icon='reload' style='margin-left: 8px'>重置</a-button>
              <a @click='handleToggleSearch' style='margin-left: 8px'>
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class='table-operator'>
      <a-button @click='handleAdd' type='primary' icon='plus'>新增</a-button>
      <a-button type='primary' icon='download' @click="handleExportXls('工资申请')">导出</a-button>
      <!--      <a-upload name='file' :showUploadList='false' :multiple='false' :headers='tokenHeader' :action='importExcelUrl'-->
      <!--                @change='handleImportExcel'>-->
      <!--        <a-button type='primary' icon='import'>导入</a-button>-->
      <!--      </a-upload>-->
      <!-- 高级查询区域 -->
    </div>

    <!-- table区域-begin -->
    <div>
      <a-table
        ref='table'
        size='middle'
        :scroll='{x:true}'
        bordered
        rowKey='id'
        :columns='columns'
        :dataSource='dataSource'
        :pagination='ipagination'
        :loading='loading'
        :rowSelection='{selectedRowKeys: selectedRowKeys, onChange: onSelectChange}'
        class='j-table-force-nowrap'
        @change='handleTableChange'>
        <template slot='salTime' slot-scope='text, record'>
          <a @click='handleDetail(record)'>{{ text }}</a>
        </template>

        <template slot='remake' slot-scope='text'>
          <j-ellipsis :value="text" :length="20"/>
        </template>
        <template slot='htmlSlot' slot-scope='text'>
          <div v-html='text'></div>
        </template>
        <template slot='imgSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无图片</span>
          <img v-else :src='getImgView(text)' height='25px' alt=''
               style='max-width:80px;font-size: 12px;font-style: italic;' />
        </template>
        <template slot='bpmStatus_dictText' slot-scope='text, record'>
          <BpmStatusTagComponent :record='record' :text='text'></BpmStatusTagComponent>
        </template>
        <template slot='fileSlot' slot-scope='text'>
          <span v-if='!text' style='font-size: 12px;font-style: italic;'>无文件</span>
          <a-button
            v-else
            :ghost='true'
            type='primary'
            icon='download'
            size='small'
            @click='downloadFile(text)'>
            下载
          </a-button>
        </template>

        <span slot='action' slot-scope='text, record'>
          <a @click='handleEdit(record)' v-if='record.bpmStatus == 1'>编辑</a>
<!--      发放权限    v-has="'HfPsSalaryApply:issue'"-->
<!--           <a-popconfirm  title="确定发放吗?" @confirm="() => handleIssue(record)" v-if='record.bpmStatus == 3&&record.issue!=="Y"'>-->
<!--              <a>发放</a>-->
<!--            </a-popconfirm>-->
<!--            <a @click="ratis(record)" v-has="'HfPsSalaryApply:issue'" v-if="record.issue === 'N' && record.bpmStatus == '3'">发放</a>-->
          <a-divider type='vertical' v-if="record.bpmStatus === '1'|| record.bpmStatus == 3&&record.issue === 'N'" />
          <a-dropdown>
            <a class='ant-dropdown-link'>更多 <a-icon type='down' /></a>
            <a-menu slot='overlay'>
              <a-menu-item>
                <a @click='handleDetail(record)'>详情</a>
              </a-menu-item>
              <a-menu-item v-if="record.bpmStatus === '1'">
                <a @click='startProcess(record)'>发起流程</a>
              </a-menu-item>
              <a-menu-item v-if="record.bpmStatus === '1'">
                <a-popconfirm title='确定删除吗?' @confirm='() => handleDelete(record.id)'>
                  <a style="color:red">删除</a>
                </a-popconfirm>
              </a-menu-item>
                <a-menu-item v-if="record.bpmStatus === '2'">
                  <a-popconfirm title='确定要作废流程吗?' @confirm='() => invalidProcess(record)'>
                  <a>作废流程</a> </a-popconfirm>
                </a-menu-item>
                <a-menu-item v-if="record.bpmStatus !== '1'" @click='handleTrack(record)'>审批进度
                </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
<!--      <a-row>-->
<!--        <a-col :span="8">-->
<!--          <a-card>-->
<!--            <a-statistic title="总金额（元）" :value="countMoney" />-->
<!--          </a-card>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-card>-->
<!--            <a-statistic title="未发（元）" :value="countNotSend" />-->
<!--          </a-card>-->
<!--        </a-col>-->
<!--        <a-col :span="8">-->
<!--          <a-card>-->
<!--            <a-statistic title="已发（元）" :value="countAlreadySend" />-->
<!--          </a-card>-->
<!--        </a-col>-->
<!--      </a-row>-->
    </div>

    <hf-ps-salary-apply-modal ref='modalForm' @ok='modalFormOk'></hf-ps-salary-apply-modal>
    <bpm-process-track-modal ref='bpmProcessTrackModal'></bpm-process-track-modal>
    <bpm-biz-task-deal-modal ref='taskDealModal' :path='path'
                             :formData='formData' @ok='handleOk'></bpm-biz-task-deal-modal>
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { JeecgBpmListMixin } from '@/mixins/JeecgBpmListMixin'
import HfPsSalaryApplyModal from './modules/HfPsSalaryApplyModal'
import { getAction, postAction } from '@/api/manage'
import BpmStatusTagComponent from '@comp/bpm/bpmStatusTagComponent'
import BpmBizTaskDealModal from '@views/modules/bpmbiz/common/BpmBizTaskDealModal'
import BpmProcessTrackModal from '@views/modules/bpmbiz/common/BpmProcessTrackModal'
import { filterMultiDictText, initDictOptions } from '@comp/dict/JDictSelectUtil'

export default {
  name: 'HfPsSalaryApplyList',
  mixins: [JeecgBpmListMixin],
  components: {
    HfPsSalaryApplyModal,
    BpmStatusTagComponent,
    BpmProcessTrackModal,
    BpmBizTaskDealModal,
    filterMultiDictText
  },
  data() {
    return {
      description: '工资申请管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '申请工资月份',
          align: 'center',
          dataIndex: 'salTime',
          scopedSlots: { customRender: 'salTime' }
        },
        {
          title: '申请人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '申请总额',
          align: 'center',
          dataIndex: 'amount',
          customRender: (text) => {
            return !text ? '0' : String(text.toFixed(2)).replace(/\B(?=(\d{3})+(?!\d))/g, ',')
          }
        },
        {
          title: '说明',
          align: 'center',
          dataIndex: 'remake',
          scopedSlots: { customRender: 'remake' }
        },
        {
          title: '流程状态',
          align: 'center',
          dataIndex: 'bpmStatus_dictText',
          scopedSlots: { customRender: 'bpmStatus_dictText' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 147,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/ps/hfPsSalaryApply/list',
        sum: '/ps/hfPsSalaryApply/sum',
        delete: '/ps/hfPsSalaryApply/delete',
        deleteBatch: '/ps/hfPsSalaryApply/deleteBatch',
        exportXlsUrl: '/ps/hfPsSalaryApply/exportXls',
        importExcelUrl: 'ps/hfPsSalaryApply/importExcel',
        startProcess: '/act/process/extActProcess/startMutilProcess',
        issue: '/ps/hfPsSalaryApply/issue',

      },
      //代码生成后需手动设置流程编码
      flowCode: 'onl_hf_ps_salary_apply',
      dictOptions: {},
      countMoney: '',
      countNotSend: '',
      countAlreadySend: '',
    }
  },
  created() {
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  methods: {
    ratis(record) {
      record.clickArchive = true //为了识别是点击了发放
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '发放'
      this.$refs.modalForm.disableSubmit = false
    },
    handleDetail: function (record) {
      record.clickArchive = false //为了识别是点击了编辑或详情
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = '工资详情'
      this.$refs.modalForm.disableSubmit = true
    },
    getSum(params) {
      getAction(this.url.sum, params).then((res) => {
        if (res.success) {
          this.countMoney = res.result.countMoney.toFixed(2)
          this.countNotSend = res.result.countNotSend.toFixed(2)
          this.countAlreadySend = res.result.countAlreadySend.toFixed(2)
        }
      })
    },
    loadData(arg) {
      if (!this.url.list) {
        this.$message.error('请设置url.list属性!')
        return
      }
      if (arg === 1) {
        this.ipagination.current = 1
      }
      var params = this.getQueryParams() //查询条件
      this.getSum(params)
      this.loading = true
      getAction(this.url.list, params).then((res) => {
        if (res.success) {
          this.dataSource = res.result.records
          if (res.result.total) {
            this.ipagination.total = res.result.total
          }
        }
        if (res.code === 510) {
          this.$message.warning(res.message)
        }
        this.loading = false
      })
    },
    startProcess(record) {
      this.$confirm({
        title: '提示',
        content: '确认提交流程吗?',
        onOk: () => {
          let params = {
            flowCode: this.flowCode,
            id: record.id,
            formUrl: 'hifar/ps/modules/HfPsSalaryApplyForm',
            formUrlMobile: ''
          }
          postAction(this.url.startProcess, params).then(res => {
            if (res.success) {
              this.$message.success(res.message)
              this.loadData()
              this.onClearSelected()
            } else {
              this.$message.warning(res.message)
            }
          }).catch((e) => {
            this.$message.warning('不识别的请求!')
          })
        }
      })
    },
    handleIssue(params) {
      if (params.bpmStatus === '3') {
        getAction(this.url.issue, { id: params.id }).then((res) => {
          this.loadData()
        })
      } else {
        this.$message.warning('流程审核已完成之后才可以发放！')
      }
    },
    initDictConfig() {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>